# 1merge
MERGE = task_1merge.cc
MERGE_LIB = libtask_1merge.so
#2add case and unroll
CASE = task_2case.cc
CASE_LIB = libtask_2case.so
#3MUL = task_mul_t.cc 
MUL =task_3mul.cc
MUL_LIB = libtask_3mul.so
#4MULG #pragma (guided)
MULG =task_4mulg.cc
MULG_LIB = libtask_4mulg.so
#5 case+avx
CASE_AVX = task_5case_avx.cc
CASE_AVX_LIB = libtask_5case_avx.so 
 #6 AVX lie 
AVXLIE = task_6avxlie.cc
AVXLIE_LIB = libtask_6avxlie.so
#7 AVX lie8
AVXLIE8 = task_7avxlie8.cc
AVXLIE8_LIB = libtask_7avxlie8.so
#8 AVX han8
AVXHAN8 = task_8avxhan8.cc
AVXHAN8_LIB = libtask_8avxhan8.so
#9 case + mulg
CASE_MULG = task_9case_mulg.cc
CASE_MULG_LIB = libtask_9case_mulg.so
#10 case + mul
CASE_MUL = task_10case_mul.cc
CASE_MUL_LIB = libtask_10case_mul.so
#11 case+avx+mulg
CASE_AVX_MULG = task_11case_avx_mulg.cc
CASE_AVX_MULG_LIB = libtask_11case_avx_mulg.so
#12 avxlie_509
AVXLIE_509 = task_12avxlie_509.cc
AVXLIE_509_LIB = libtask_12avxlie_509.so
#13 avxlie8_509
AVXLIE8_509 = task_13avxlie8_509.cc
AVXLIE8_509_LIB = libtask_13avxlie8_509.so

#14 avxlie_509_mulg
AVXLIE_509_MULG = task_14avxlie_509_mulg.cc
AVXLIE_509_MULG_LIB = libtask_14avxlie_509_mulg.so
#15 avxlie8_509_mulg
AVXLIE8_509_MULG = task_15avxlie8_509_mulg.cc
AVXLIE8_509_MULG_LIB = libtask_15avxlie8_509_mulg.so
#16 avxlie_509_mul
AVXLIE_509_MUL = task_16avxlie_509_mul.cc
AVXLIE_509_MUL_LIB = libtask_16avxlie_509_mul.so
#
SPREAD_TEST = task_spread_test.cc
SPREAD_TEST_LIB = task_spread_test.so
SEED = 88
CLOSE_TEST = task_close_test.cc
CLOSE_TEST_LIB = task_close_test.so
LOOP = 100
NUM = 1024
TOL = 1e-13
# 赛方的版本
gold: libcompetition.out 
	./testApp -load ./libcompetition.out -loop $(LOOP) -matrixnum $(NUM) -seed $(SEED)  -tol $(TOL)
#1 merge 合并taskB中多个循环+临时变量
merge:$(MERGE)
	g++ $(MERGE) -O2 -shared -fPIC  -o $(MERGE_LIB)
merge_run:$(MERGE_LIB)
	./testApp -load ./$(MERGE_LIB) -loop $(LOOP) -matrixnum $(NUM) -seed $(SEED)  -tol $(TOL)
#2 case：case做第三层的循环展开
case:$(CASE)
	g++ $(CASE) -O2 -shared -fPIC  -o $(CASE_LIB)
case_run:$(CASE_LIB)
	./testApp -load ./$(CASE_LIB) -loop $(LOOP) -matrixnum $(NUM) -seed $(SEED)  -tol $(TOL)
#3 mul ：一般的8线程
mul:$(MUL)
	g++ $(MUL) -O2 -fopenmp -mavx -std=c++11 -shared -fPIC  -o $(MUL_LIB)
mul_run:$(MUL_LIB)
	./testApp -load ./$(MUL_LIB) -loop $(LOOP) -matrixnum $(NUM) -seed $(SEED)  -tol $(TOL)
#4 mulg ：schedule(guided) 调度8线程
mulg:$(MULG)
	g++ $(MULG) -O2 -fopenmp -shared -fPIC  -o $(MULG_LIB)
mulg_run:$(MULG_LIB)
	./testApp -load ./$(MULG_LIB) -loop $(LOOP) -matrixnum $(NUM) -seed $(SEED)  -tol $(TOL)
#5 case+avx ：case循环展开+avx行加速
cavx:$(CASE_AVX)
	g++ $(CASE_AVX) -O2 -mavx -shared -fPIC  -o $(CASE_AVX_LIB)
cavx_run:$(CASE_AVX_LIB)
	./testApp -load ./$(CASE_AVX_LIB) -loop $(LOOP) -matrixnum $(NUM)  -seed $(SEED)  -tol $(TOL)
#6 avxlie ：avx先算4行首元素，后普通乘加
avxl:$(AVXLIE)
	g++ $(AVXLIE) -O2 -mavx -shared -fPIC  -o $(AVXLIE_LIB)
avxl_run:$(AVXLIE_LIB)
	./testApp -load ./$(AVXLIE_LIB) -loop $(LOOP) -matrixnum $(NUM)  -seed $(SEED)  -tol $(TOL)
#7 avxlie8 avx512先算8行元素，后普通乘加
avxl8:$(AVXLIE8)
	g++ $(AVXLIE8) -O2 -mavx512f -shared -fPIC  -o $(AVXLIE8_LIB)
avxl8_run:$(AVXLIE8_LIB)
	./testApp -load ./$(AVXLIE8_LIB) -loop $(LOOP) -matrixnum $(NUM)  -seed $(SEED)  -tol $(TOL)
# 8avxhan8 每行用avx512加速
avxh8:$(AVXHAN8)
	g++ $(AVXHAN8) -O2 -mavx512f -shared -fPIC  -o $(AVXHAN8_LIB)
avxh8_run:$(AVXHAN8_LIB)
	./testApp -load ./$(AVXHAN8_LIB) -loop $(LOOP) -matrixnum $(NUM)  -seed $(SEED)  -tol $(TOL)
#9 case mulg case循环展开+guided调度8线程
casemg:$(CASE_MULG)
	g++ $(CASE_MULG) -O2 -fopenmp -shared -fPIC  -o $(CASE_MULG_LIB)
casemg_run:$(CASE_MULG_LIB)
	./testApp -load ./$(CASE_MULG_LIB) -loop $(LOOP) -matrixnum $(NUM) -seed $(SEED)  -tol $(TOL)
#10 case mul case循环展开+一般8线程
casem:$(CASE_MUL)
	g++ $(CASE_MUL) -O2 -fopenmp -mavx -shared -fPIC  -o $(CASE_MUL_LIB)
casem_run:$(CASE_MUL_LIB)
	./testApp -load ./$(CASE_MUL_LIB) -loop $(LOOP) -matrixnum $(NUM) -seed $(SEED)  -tol $(TOL)
#11 case+avx+mulg case循环展开+avx行加速+guided调度8线程
cavxmg:$(CASE_AVX_MULG)
	g++ $(CASE_AVX_MULG) -O2 -mavx -fopenmp -shared -fPIC  -o $(CASE_AVX_MULG_LIB)
cavxmg_run:$(CASE_AVX_MULG_LIB)
	./testApp -load ./$(CASE_AVX_MULG_LIB) -loop $(LOOP) -matrixnum $(NUM)  -seed $(SEED)  -tol $(TOL)
#12 avxlie+509 根据矩阵类型不同用avx4行并行
avxl509:$(AVXLIE_509)
	g++ $(AVXLIE_509) -O2 -mavx -shared -fPIC  -o $(AVXLIE_509_LIB)
avxl509_run:$(AVXLIE_LIB)
	./testApp -load ./$(AVXLIE_509_LIB) -loop $(LOOP) -matrixnum $(NUM)  -seed $(SEED)  -tol $(TOL)
#13 avxlie8+509 根据矩阵类型不同用avx8行并行
avxl8509:$(AVXLIE8_509)
	g++ $(AVXLIE8_509) -O2 -mavx512f -shared -fPIC  -o $(AVXLIE8_509_LIB)
avxl8509_run:$(AVXLIE8_509_LIB)
	./testApp -load ./$(AVXLIE8_509_LIB) -loop $(LOOP) -matrixnum $(NUM)  -seed $(SEED)  -tol $(TOL)
#14 根据矩阵类型用不同avx4行并行+guided调度8线程
avxl509mulg:$(AVXLIE_509_MULG)
	g++ $(AVXLIE_509_MULG) -O2 -mavx -fopenmp -shared -fPIC  -o $(AVXLIE_509_MULG_LIB)
avxl509mulg_run:$(AVXLIE_LIB)
	./testApp -load ./$(AVXLIE_509_MULG_LIB) -loop $(LOOP) -matrixnum $(NUM)  -seed $(SEED)  -tol $(TOL)
#15 根据矩阵类型，用不同avx8行并行+guided调度8线程
avxl8509mulg:$(AVXLIE8_509_MULG)
	g++ $(AVXLIE8_509_MULG) -O2 -mavx512f -fopenmp -shared -fPIC  -o $(AVXLIE8_509_MULG_LIB)
avxl8509mulg_run:$(AVXLIE8_509_MULG_LIB)
	./testApp -load ./$(AVXLIE8_509_MULG_LIB) -loop $(LOOP) -matrixnum $(NUM)  -seed $(SEED)  -tol $(TOL)
#16
avxl509mul:$(AVXLIE_509_MUL)
	g++ $(AVXLIE_509_MUL) -O2 -mavx -fopenmp -shared -fPIC  -o $(AVXLIE_509_MUL_LIB)
avxl509mul_run:$(AVXLIE_509_MUL_LIB)
	./testApp -load ./$(AVXLIE_509_MUL_LIB) -loop $(LOOP) -matrixnum $(NUM)  -seed $(SEED)  -tol $(TOL)
spread_test:$(SPREAD_TEST)
	g++ $(SPREAD_TEST) -O2 -mavx -fprefetch-loop-arrays -fopenmp -shared -fPIC -o $(SPREAD_TEST_LIB)
close_test:$(CLOSE_TEST)
	g++ $(CLOSE_TEST) -O2 -mavx -fprefetch-loop-arrays -fopenmp -shared -fPIC -o $(CLOSE_TEST_LIB)
test_run:$(TEST_LIB)
	numactl --interleave=all ./testApp -load ./$(TEST_LIB) -loop $(LOOP) -matrixnum $(NUM) -seed $(SEED) -tol $(TOL)

clean:
	rm -f *.so *.o

